/*
 * socktool.h
 *
 *  Copyright (C) 2022-2025 BOQ Inc. All rights reserved.
 *
 *  Created on: 2025年6月25日
 *      Author: fitch
 */

#ifndef SRC_SOCKTOOL_H_
#define SRC_SOCKTOOL_H_

#ifdef __cplusplus
extern "C" {
#endif

/*
 * 获取指定IP对应网卡的MAC地址
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @ip: 需要查询的IP地址
 * @mac: 返回6字节mac地址, 如unsigned char mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB};
 * @ret: 0: 成功, -1: 失败
 */
int net_eth_dst_get_mac(const char *eth_name, char *ip, unsigned char *mac);

/*
 * 获取网卡的MAC地址
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @mac: 返回6字节mac地址, 如unsigned char mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB};
 * @ret: 0: 成功, -1: 失败
 */
int net_eth_get_mac(const char *eth_name, unsigned char *mac);

/*
 * 修改网卡的MAC地址
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @mac: 6字节mac地址, 如unsigned char mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xAB};
 *       类似于 ifconfig ethx hw ether 12:34:56:78:90:AB
 * @ret: 0: 成功, -1: 失败
 */
int net_eth_set_mac(const char *eth_name, unsigned char *mac);

/*
 * 获取网卡ip地址
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @ip: 返回4字节ip地址, 如char ip[4] = {10, 10, 10, 3};即: 10.10.10.3
 * @netmask: 返回4字节netmask地址, 如char netmask[4] = {0xff, 0xff, 0xff, 0};即: 255.255.255.0
 * @ret: 0: 成功, -1: 不能获取ip地址
 */
int net_eth_get_ipv4_addr(const char *eth_name, unsigned char *ip, unsigned char *netmask);

/*
 * 设置网卡ip地址
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @ip: 返回4字节ip地址, 如char ip[4] = {10, 10, 10, 3};即: 10.10.10.3
 * @netmask: 返回4字节netmask地址, 如char netmask[4] = {0xff, 0xff, 0xff, 0};即: 255.255.255.0
 * @ret: 0: 成功, -1: 不能获取ip地址
 */
int net_eth_set_ipv4_addr(const char *eth_name, unsigned char *ip, unsigned char *netmask);

/*
 * 添加默认网关
 * @gw: 4字节地址, 如char gw[4] = {10, 10, 10, 1};即: 10.10.10.1
 * @ret: 0: 成功, -1: 失败
 * 
 * 注意: 如果想删除网卡相关的所有路由表可以直接把网卡down,即ifconfig ethx down
 */
int net_route_add_default_gateway(const char *eth_name, unsigned char *gw);
 
/*
 * 删除默认网关
 * @gw: 4字节地址, 如char gw[4] = {10, 10, 10, 1};即: 10.10.10.1
 * @ret: 0: 成功, -1: 失败
 * 
 * 注意: 如果想删除网卡相关的所有路由表可以直接把网卡down,即ifconfig ethx down
 */
int net_route_del_default_gateway(const char *eth_name, unsigned char *gw);

/*
 * 获取默认网关
 * @eth_name: 网卡名, 如:eth0, wlan0..
 * @gw: 获取4字节地址, 如char gw[4] = {10, 10, 10, 1};即: 10.10.10.1
 * @ret: 0: 成功, -1: 失败
 * 
 * 注意: 如果想删除网卡相关的所有路由表可以直接把网卡down,即ifconfig ethx down
 */
int net_route_get_default_gateway(const char *eth_name, unsigned char *gw);

#ifdef __cplusplus
}
#endif

#endif /* SRC_SOCKTOOL_H_ */
